Add Pijul support to cargo
authorPaul Woolcock <paul@woolcock.us>
Fri, 31 Mar 2017 15:35:58 +0000 (11:35 -0400)
committerPaul Woolcock <paul@woolcock.us>
Fri, 31 Mar 2017 18:22:04 +0000 (14:22 -0400)
[Pijul](https://pijul.org) is a version control system written in Rust. This commit adds the ability to create a cargo project using pijul as the vcs for the project.

To use it, run `cargo new my-awesome-project --vcs=pijul`

src/bin/new.rs
src/cargo/ops/cargo_new.rs
src/cargo/util/mod.rs
src/cargo/util/vcs.rs

index 865985e367dfd83f8ec5c1c89f2e889356b0521d..834134ba0a79abc183f123c1c0e37b8695318418 100644 (file)
@@ -27,7 +27,7 @@ Usage:
 Options:
     -h, --help          Print this message
     --vcs VCS           Initialize a new repository for the given version
-                        control system (git or hg) or do not initialize any version
+                        control system (git, hg, or pijul) or do not initialize any version
                         control at all (none) overriding a global configuration.
     --bin               Use a binary (application) template
     --lib               Use a library template
index 989035cf9021a1baa39fa1da6104effaa9e2ac72..088e4c5b44c2e2bbf128cd4ece899c66c976e1fd 100644 (file)
@@ -10,13 +10,13 @@ use git2::Config as GitConfig;
 use term::color::BLACK;
 
 use core::Workspace;
-use util::{GitRepo, HgRepo, CargoResult, human, ChainError, internal};
+use util::{GitRepo, HgRepo, PijulRepo, CargoResult, human, ChainError, internal};
 use util::{Config, paths};
 
 use toml;
 
 #[derive(Clone, Copy, Debug, PartialEq)]
-pub enum VersionControl { Git, Hg, NoVcs }
+pub enum VersionControl { Git, Hg, Pijul, NoVcs }
 
 pub struct NewOptions<'a> {
     pub version_control: Option<VersionControl>,
@@ -45,6 +45,7 @@ impl Decodable for VersionControl {
         Ok(match &d.read_str()?[..] {
             "git" => VersionControl::Git,
             "hg" => VersionControl::Hg,
+            "pijul" => VersionControl::Pijul,
             "none" => VersionControl::NoVcs,
             n => {
                 let err = format!("could not decode '{}' as version control", n);
@@ -331,10 +332,15 @@ pub fn init(opts: NewOptions, config: &Config) -> CargoResult<()> {
             num_detected_vsces += 1;
         }
 
+        if fs::metadata(&path.join(".pijul")).is_ok() {
+            version_control = Some(VersionControl::Pijul);
+            num_detected_vsces += 1;
+        }
+
         // if none exists, maybe create git, like in `cargo new`
 
         if num_detected_vsces > 1 {
-            bail!("both .git and .hg directories found \
+            bail!("more than one of .hg, .git, or .pijul directories found \
                               and the ignore file can't be \
                               filled in as a result, \
                               specify --vcs to override detection");
@@ -401,6 +407,11 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> {
             }
             paths::append(&path.join(".hgignore"), ignore.as_bytes())?;
         },
+        VersionControl::Pijul => {
+            if !fs::metadata(&path.join(".pijul")).is_ok() {
+                PijulRepo::init(path, config.cwd())?;
+            }
+        },
         VersionControl::NoVcs => {
             fs::create_dir_all(path)?;
         },
index 572398ba240edd45ed97a9bfc7cb1dec94d5562e..27da14148c26c363b2f69362129aae5105abae4a 100644 (file)
@@ -17,7 +17,7 @@ pub use self::rustc::Rustc;
 pub use self::sha256::Sha256;
 pub use self::to_semver::ToSemver;
 pub use self::to_url::ToUrl;
-pub use self::vcs::{GitRepo, HgRepo};
+pub use self::vcs::{GitRepo, HgRepo, PijulRepo};
 pub use self::read2::read2;
 
 pub mod config;
index 730200316a09334f4d4cc99cda46ace63178321d..61a4b1c394292a3552d27eb552b732da9684dfd5 100644 (file)
@@ -6,6 +6,7 @@ use util::{CargoResult, process};
 
 pub struct HgRepo;
 pub struct GitRepo;
+pub struct PijulRepo;
 
 impl GitRepo {
     pub fn init(path: &Path, _: &Path) -> CargoResult<GitRepo> {
@@ -28,3 +29,9 @@ impl HgRepo {
     }
 }
 
+impl PijulRepo {
+    pub fn init(path: &Path, cwd: &Path) -> CargoResult<PijulRepo> {
+        process("pijul").cwd(cwd).arg("init").arg(path).exec()?;
+        Ok(PijulRepo)
+    }
+}